package chapter4.eg9;

import java.util.Properties;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.clients.producer.Producer;
import org.apache.kafka.clients.producer.ProducerRecord;

public class ProducerTest {

  public static void main(String[] args) {
    Properties properties = new Properties();
    properties.put("bootstrap.servers", "localhost:9092,localhost:9093,localhost:9094");
    properties.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    properties.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
    properties.put("acks", "-1");
    properties.put("retries", 3);
    properties.put("batch.size", 323840);
    properties.put("linger.ms", 10);
    properties.put("buffer.memory", 33554432);
    properties.put("max.block.ms", 3000);

    Producer<String, String> producer = new KafkaProducer<>(properties);
    for (int i = 0; i < 100; i++) {
      producer.send(new ProducerRecord<>("my-topic", String.valueOf(i), String.valueOf(i)));
    }

    producer.close();
  }

}
